/*************************************************************************
	> File Name: 5.E.cpp
	> Author: hug
	> Mail: hug@haizeix.com
	> Created Time: 六  2/15 21:21:58 2025
 ************************************************************************/

#include <iostream>
#include <vector>
using namespace std;

int n, k;
int min_prime[1000005], prime[1000005];
int a[2000005], cnt[1000005], ans[1000005];
vector<int> fac[1000005];

void init_prime() {
    for (int i = 2; i <= 1000000; i++) {
        if (prime[i] == 0) {
            prime[++prime[0]] = i;
            min_prime[i] = i;
        }
        for (int j = 1; j <= prime[0]; j++) {
            if (prime[j] * i > 1000000) break;
            prime[prime[j] * i] = 1;
            min_prime[prime[j] * i] = prime[j];
            if (i % prime[j] == 0) break;
        }
    }
    return ;
}

void getFac(int x) {
    if (fac[x].size()) return ;
    fac[x].push_back(1);
    int xx = x;
    while (xx != 1) {
        int y = min_prime[xx], last, ind = 0;
        while (xx % y == 0) {
            last = fac[x].size();
            for (int i = ind; i < last; i++) {
                fac[x].push_back(y * fac[x][i]);
            }
            ind = last;
            xx /= y;
        }
    }
    return ;
}

void count_fac(int x) {
    getFac(x);
    for (int i = 0; i < fac[x].size(); i++) {
        cnt[fac[x][i]] += 1;
    }
    return ;
}

int getAns(int x) {
    if (ans[x]) return ans[x];
    ans[x] = 1;
    for (int i = 0; i < fac[x].size(); i++) {
        if (cnt[fac[x][i]] >= k) ans[x] = max(ans[x], fac[x][i]);
    }
    return ans[x];
}

int main() {
    init_prime();
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        count_fac(a[i]);
    }
    for (int i = 1; i <= n; i++) {
        cout << getAns(a[i]) << endl;
    }
    return 0;
}
